// fix-imports.cjs
const fs = require('fs');
const path = require('path');

// 这里写之前 check-import-fix 输出的错误列表
const fixes = [
  {
    file: 'src/views/nursing/oldPeople/index.vue',
    wrong: "@/components/switchBar/SwitchBartop.vue",
    correct: "@/views/nursing/floor/components/SwitchBartop.vue"
  },
  {
    file: 'src/main.js',
    wrong: "@/utils/request",
    correct: "@/utils/request.js"
  },
  // TODO: 根据 check-import-fix 的输出，把所有错误路径都加进来
];

fixes.forEach(({ file, wrong, correct }) => {
  const absPath = path.resolve(file);
  if (!fs.existsSync(absPath)) {
    console.log(`⚠️ 文件不存在: ${file}`);
    return;
  }

  let content = fs.readFileSync(absPath, 'utf-8');
  const regex = new RegExp(wrong.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g');

  if (regex.test(content)) {
    content = content.replace(regex, correct);
    fs.writeFileSync(absPath, content, 'utf-8');
    console.log(`✅ 修复: ${file}`);
  } else {
    console.log(`ℹ️ 未匹配到: ${file}`);
  }
});

